package eg.com.itiga.ui.beans;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

public class LoginForm extends org.apache.struts.action.ActionForm {

	private final int lengthPassword = 6;
	
	private String userName;
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	private String password;
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
    public LoginForm () {
    }

    public void reset(ActionMapping actionMapping, HttpServletRequest request) {
        // TODO: Write method body
        //throw new UnsupportedOperationException("Method is not implemented");
    }

    public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest request) {
        // TODO: Write method body
        //throw new UnsupportedOperationException("Method is not implemented");
    	ActionErrors errors = new ActionErrors();
    	if(userName == null || userName.equals(""))
    		errors.add("userNameError",new ActionError("EmptyUserName"));
    	if(password == null || password.equals(""))
    		errors.add("passwordError",new ActionError("EmptyPassword"));
    	if(password.length() < lengthPassword)
    		errors.add("InvalidPasswordLen",new ActionError("InvalidPassword"));
    	return errors;
    }


}